using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using Utilities;

namespace GPX
{
    public partial class EditWaypointDialog : FormEx
    {
        private WayPoint _WayPoint;
        public WayPoint WayPoint
        {
            get { return _WayPoint; }
            set { _WayPoint = value; }
        }

        public EditWaypointDialog()
        {
            InitializeComponent();
            if (System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Runtime)
            {
                Localizer.LocalizeControl(this, GPXAppResourceManager.ResourceManager);
            }
        }

        private void EditWaypointDialog_Load(object sender, EventArgs e)
        {
            DataToUI();
        }

        private void DataToUI()
        {
            txtIndex.Text = _WayPoint.Index.ToString();
            txtElevation.Text = _WayPoint.Elevation.ToString();
            txtLatitude.Text = _WayPoint.Latitude.ToString();
            txtLongitude.Text = _WayPoint.Longitude.ToString();
            txtName.Text = _WayPoint.Name;
            txtTime.Text = _WayPoint.Time.ToString();
        }

        private void DataFromUI()
        {
            _WayPoint.Elevation = decimal.Parse(txtElevation.Text);
            _WayPoint.Latitude = decimal.Parse(txtLatitude.Text);
            _WayPoint.Longitude = decimal.Parse(txtLongitude.Text);
            _WayPoint.Name = txtName.Text.Trim();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                DataFromUI();
                DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                Utils.HandleException(ex);
            }
        }
    }
}